<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:c="http://java.sun.com/jsp/jstl/core"
	xmlns:p="http://primefaces.org/ui"
	template="/templates/masterLayout.xhtml">

	<ui:define name="pageTitle">#{out.index_title}</ui:define>

	<ui:define name="head-extra">
		<!-- custom css -->
	</ui:define>

	<ui:define name="content">

		<p:dialog header="Order" widgetVar="orderDialog" modal="true"
			height="600" width="800">
			<h:form id="orderView">
				<h:outputText value="Order" />
				<p:dataTable var="data" value="#{leaderController.info.need}"
					rowStyleClass="#{data.need==0?'ready_row':'not_ready_row'}">
					<p:column headerText="Ready?">
						<h:outputText value="#{data.need==0?true:false}" />
					</p:column>
					<p:column headerText="Product">
						<h:outputText value="#{data.product.name}" />
					</p:column>
					<p:column headerText="Need quantity">
						<h:outputText value="#{data.originalQuantity}" />
					</p:column>
					<p:column headerText="Need">
						<h:outputText value="#{data.need}" />
					</p:column>
					<p:column headerText="Ready">
						<h:outputText value="#{data.readyQuantity}" />
					</p:column>
					<p:column headerText="IN WH">
						<h:outputText value="#{data.inWHQuantity}" />
					</p:column>
					<p:column headerText="Keep Product">
						<p:commandButton
							disabled="#{data.inWHQuantity==0 || data.need==0}" value="Keep"
							action="#{leaderController.keepProduct(data, data.need)}"
							update=":orderView :orderForm" />
					</p:column>
				</p:dataTable>
				<br />
				<p:panelGrid columns="2">
					<h:outputText value="Partner name:" />
					<h:outputText style="color:red;"
						value="#{leaderController.selectedOrder.partnerDTO.name}" />
					<h:outputText value="Status:" />
					<h:outputText style="color:red;"
						value="#{leaderController.selectedOrder.status}" />
				</p:panelGrid>
				<br />
				<p:panelGrid columns="4">
					<p:commandButton value="Transport"
						disabled='#{!leaderController.info.readyForTransport || 
						"TRANSPORT".equals(leaderController.selectedOrder.status) || 
						"READY".equals(leaderController.selectedOrder.status) || 
						"DURINGTRANSPORT".equals(leaderController.selectedOrder.status) 
						}'
						action="#{leaderController.transportOrder()}"
						update=":orderForm :orderView" />
					<p:commandButton value="Need import"
						disabled='#{leaderController.info.importReady ||leaderController.info.readyForTransport || 
						"NEEDPRODUCT".equals(leaderController.selectedOrder.status) 
						}'
						action="#{leaderController.needProduct()}"
						update=":orderForm :orderView" />
					<!-- 
					<p:commandButton value="Keep product from wh" />
					 -->
					<p:commandButton value="Remove order" />
				</p:panelGrid>
			</h:form>
		</p:dialog>
		<h:form id="orderForm">
			<p:growl id="msgs" showDetail="true" />
			<p:dataTable id="orderTable" var="currentOrder"
				value="#{leaderBean.lazyOrderModel}" selectionMode="single"
				selection="#{leaderController.selectedOrder}"
				rowKey="#{currentOrder.id}" paginator="true" rows="10"
				paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
				rowsPerPageTemplate="5,10,15" lazy="true"
				emptyMessage="#{out.empty_message}"
				rowStyleClass="#{currentOrder.info.importReady?'ok':'notok'}">
				<p:ajax event="rowSelect" />

				<p:column headerText="#{out.orders_form_name}"
					sortBy="#{currentOrder.name}" filterBy="#{currentOrder.name}">
					<h:outputText value="#{currentOrder.name}" />
				</p:column>
				<p:column headerText="#{out.orders_form_date}"
					sortBy="#{currentOrder.date}">
					<h:outputText value="#{currentOrder.date}" />
				</p:column>
				<p:column headerText="Expected income"
					sortBy="#{currentOrder.costOfAll}">
					<h:outputText value="#{currentOrder.costOfAll}" />
				</p:column>
				<p:column headerText="#{out.orders_form_status}"
					sortBy="#{currentOrder.status}" filterBy="#{currentOrder.status}">
					<h:outputText value="#{currentOrder.status}" />
					<h:outputText rendered="#{currentOrder.info.importReady}"
						value=" - OK" />
				</p:column>
			</p:dataTable>
			<p:commandButton value="SHOW"
				action="#{leaderController.initSelectedOrder()}"
				onclick="PF('orderDialog').show()" update=":orderView" />
		</h:form>

	</ui:define>
</ui:composition>